//
//  HomePageVM.m
//  WanCaiC8
//
//  Created by tangang on 2018/2/28.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "HomePageVM.h"
#import "Home_LotteryModel.h"
//#import "HomeNavigationByLhcModel.h"
@implementation HomePageVM

/***** Start ************************盈彩网首页****************************/

- (void)getNavigationByLhcSuccess:(SuccessBlock)success Fail:(FailBlock)fail{
    
    
    [self GET_Field_Url:@"api/News/GetNavigationByLhc" Params:nil successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            NSArray *arr=[returnValue objectForKey:@"Data"];
          
                success([HomeNavigationByLhcModel mj_objectArrayWithKeyValuesArray:arr]);
     
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
    
}


/***** End   ************************盈彩网首页****************************/


- (void)getLotteryTypeListWithParentId:(NSString *)parentId Success:(SuccessBlock)success Fail:(FailBlock)fail{
    if (self.total.count>0) {
        success(self.total);
    }else{
        WS(weakSelf);
        [self GET_Field_Url:@"api/Common/GetLotteryTypeList" Params:@{@"parentId":parentId} successBlock:^(id returnValue) {
            if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
                NSArray *arr=[returnValue objectForKey:@"Data"];
                if ([parentId isEqualToString:@""]) {
                    [weakSelf.total addObjectsFromArray:[LotteryTypeModel mj_objectArrayWithKeyValuesArray:arr]];
                    success(weakSelf.total);
                }else{
                    success([LotteryTypeModel mj_objectArrayWithKeyValuesArray:arr]);
                }
            }else{
                [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
                fail(nil,nil);
            }
        } failBlock:^(NSString *errorMessage, NSError *error) {
            [SVProgressHUD showErrorWithStatus:errorMessage];
            fail(nil,nil);
        }];
    }
}

- (void)getPlayList:(NSString *)lType andSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Common/GetPlayList" Params:@{@"lType":lType} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            NSArray *arr=[returnValue objectForKey:@"Data"];
            success([LotteryPlayModel mj_objectArrayWithKeyValuesArray:arr]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getHomeLotteryList:(NSString *)parentId andSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Common/GetIndexLotteryList" Params:@{@"parentId":parentId} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            NSArray *arr=[returnValue objectForKey:@"Data"];
            success([Home_LotteryModel mj_objectArrayWithKeyValuesArray:arr]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getFansBangList:(NSString *)type andPageIndex:(NSInteger)pageIndex andSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Personal/GetFansBangList" Params:@{@"type":type,@"pageIndex":@(pageIndex),@"pageSize":@100} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            NSArray *arr=[returnValue objectForKey:@"Data"];
            success([RankingUserModel mj_objectArrayWithKeyValuesArray:arr]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getMyFansBangRanking:(NSString *)type andSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Personal/GetMyFanBangRank" Params:@{@"type":type} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([RankingUserModel mj_objectWithKeyValues:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}


- (void)getLotteryInfoWithId:(NSString *)lType Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Common/GetLotteryInfo" Params:@{@"lType":lType} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([Home_LotteryModel mj_objectWithKeyValues:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getHighMasterListWithId:(NSInteger)lType andQueryType:(NSInteger)queryType Success:(SuccessBlock)success andFail:(FailBlock)fail{
    NSString *query=@"day";
    if (queryType==1) {
        query=@"week";
    }else if (queryType==2){
        query=@"month";
    }else if (queryType==3){
        query=@"all";
    }
    [self GET_Field_Url:@"api/Leaderboard/GetHighMasterList" Params:@{@"lType":@(lType),@"queryType":query} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([RankingUserModel mj_objectArrayWithKeyValuesArray:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getMyMasterBangRanking:(NSInteger)queryType andLType:(NSInteger)lType andSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    NSString *query=@"day";
    if (queryType==1) {
        query=@"week";
    }else if (queryType==2){
        query=@"month";
    }else if (queryType==3){
        query=@"all";
    }
    [self GET_Field_Url:@"api/Leaderboard/GetMyHighMaster" Params:@{@"lType":@(lType),@"queryType":query} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([RankingUserModel mj_objectWithKeyValues:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getIntegralListWithQueryType:(NSInteger)queryType Success:(SuccessBlock)success andFail:(FailBlock)fail{
    NSString *query=@"day";
    if (queryType==1) {
        query=@"week";
    }else if (queryType==2){
        query=@"month";
    }else if (queryType==3){
        query=@"all";
    }
    [self GET_Field_Url:@"api/Leaderboard/GetIntegralList" Params:@{@"queryType":query} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([RankingUserModel mj_objectArrayWithKeyValuesArray:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getIntegralBangWithQueryType:(NSInteger)queryType Success:(SuccessBlock)success andFail:(FailBlock)fail{
    NSString *query=@"day";
    if (queryType==1) {
        query=@"week";
    }else if (queryType==2){
        query=@"month";
    }else if (queryType==3){
        query=@"all";
    }
    [self GET_Field_Url:@"api/Leaderboard/GetMyRank" Params:@{@"queryType":query} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([RankingUserModel mj_objectWithKeyValues:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getProfitRewardListWithId:(NSInteger)lType andQueryType:(NSInteger)queryType andRType:(NSInteger)RType Success:(SuccessBlock)success andFail:(FailBlock)fail{
    NSString *query=@"day";
    if (queryType==1) {
        query=@"week";
    }else if (queryType==2){
        query=@"month";
    }else if (queryType==3){
        query=@"all";
    }
    [self GET_Field_Url:@"api/Leaderboard/GetProfitRewardList" Params:@{@"lType":@(lType),@"queryType":query,@"RType":@(RType)} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([RankingUserModel mj_objectArrayWithKeyValuesArray:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getMyProfitRewardBangWithId:(NSInteger)lType andQueryType:(NSInteger)queryType andRType:(NSInteger)RType Success:(SuccessBlock)success andFail:(FailBlock)fail{
    NSString *query=@"day";
    if (queryType==1) {
        query=@"week";
    }else if (queryType==2){
        query=@"month";
    }else if (queryType==3){
        query=@"all";
    }
    [self GET_Field_Url:@"api/Leaderboard/GetMyProfitReward" Params:@{@"lType":@(lType),@"queryType":query,@"RType":@(RType)} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([RankingUserModel mj_objectWithKeyValues:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getHotNewsWithCount:(NSInteger)count andSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/News/GetHotNewsList" Params:@{@"count":@(count)} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([NewsModel mj_objectArrayWithKeyValuesArray:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getNewsInfoWithId:(NSString *)ID andSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/News/GetNewsType" Params:@{@"id":ID} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([NewsLottryTypeModel mj_objectWithKeyValues:[returnValue objectForKey:@"Data"]]);
        }else{
//            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getVersionWithId:(NSString *)Code andSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Version/Checkver" Params:@{@"appCode":Code} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([returnValue objectForKey:@"Data"]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (NSMutableArray *)total{
    if (!_total) {
        _total=[[NSMutableArray alloc]init];
    }
    return _total;
}

static HomePageVM *n_manager=nil;
+ (HomePageVM *)manage{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        n_manager=[[HomePageVM alloc]init];
    });
    return n_manager;
}
@end
